home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <stdio.h>
- #include <Inventor/SoDB.h>
- #include "AudioNode.h"
-
- SO_SUBNODE_ID_VARS(AudioNode);
- SO_SUBNODE_FIELD_VARS(AudioNode);
- SO_SUBNODE_ID_METHODS(AudioNode);
- SO_SUBNODE_FIELD_METHODS(AudioNode);
- SO_SF_ENUM_VARS(AudioNode, 2);
-
-
- void
- AudioNode::initClass() {
- SO_SUBNODE_INIT_ID(AudioNode, "AudioNode", SoNode);
- }
-
- AudioNode::AudioNode() {
- SO_SUBNODE_BEGIN_PROTOTYPE(AudioNode);
- SO_SUBNODE_INIT_FIELDS(AudioNode);
- SO_SUBNODE_ADD_FIELD(filename, (""));
- SO_SUBNODE_ADD_FIELD(timeLength, (0.0));
- SO_SUBNODE_ADD_FIELD(inTime, (0.0));
- SO_SUBNODE_ADD_FIELD(outTime, (0.0));
- SO_SUBNODE_ADD_FIELD(maxOutputLevel, (1.0));
- SO_SUBNODE_ADD_FIELD(rude, (NOPE));
- SO_SUBNODE_ADD_FIELD(loop, (NOPE));
- SO_SUBNODE_ADD_FIELD(sproc, (YUP));
- SO_SF_ENUM_SET(AudioNode, 0, YUP, "YUP");
- SO_SF_ENUM_SET(AudioNode, 1, NOPE, "NOPE");
- SO_SUBNODE_END_PROTOTYPE();
- SO_SUBNODE_INIT_FROM_FIELD_DATA();
- SO_SF_ENUM_SET_ENUMS(AudioNode, loop, 2);
- SO_SF_ENUM_SET_ENUMS(AudioNode, rude, 2);
- SO_SF_ENUM_SET_ENUMS(AudioNode, sproc, 2);
-
- // set old versions of fields for datacb
- oldtimeLength = timeLength.getValue();
- oldinTime = inTime.getValue();
- oldoutTime = outTime.getValue();
- oldmaxOutputLevel = maxOutputLevel.getValue();
- OldFilename = filename.getValue();
- fnamechange = tlchange = itchange = otchange = molchange = 0;
-
- // set the DATA sensor
- dsensor = new SoDataSensor(AudioNode::DataCB, this);
- dsensor->attach(this);
- dsensor->setDelay(FALSE);
- dsensor->schedule();
-
- pc = NULL;
- }
-
- AudioNode::~AudioNode() {
- #ifdef DEBUG
- fprintf(stderr, "~AudioNode\n");
- #endif
- dsensor->unschedule();
- }
-
- void
- AudioNode::DataCB(void *objPtr, SoSensor *)
- {
- #ifdef DEBUG
- fprintf(stderr, "AudioNode::DataCB\n");
- #endif
-
- AudioNode *obj = (AudioNode *) objPtr;
-
- if (obj->filename.getValue() != obj->OldFilename) {
- obj->OldFilename = obj->filename.getValue();
- obj->fnamechange = 1;
- #ifdef DEBUG
- fprintf(stderr, "filename changed\n");
- #endif
- }
- if (obj->timeLength.getValue() != obj->oldtimeLength) {
- obj->oldtimeLength = obj->timeLength.getValue();
- obj->tlchange = 1;
- #ifdef DEBUG
- fprintf(stderr, "timelength changed\n");
- #endif
- }
- if (obj->inTime.getValue() != obj->oldinTime) {
- obj->oldinTime = obj->inTime.getValue();
- obj->itchange = 1;
- #ifdef DEBUG
- fprintf(stderr, "inTime changed\n");
- #endif
- }
- if (obj->outTime.getValue() != obj->oldoutTime) {
- obj->oldoutTime = obj->outTime.getValue();
- obj->otchange = 1;
- #ifdef DEBUG
- fprintf(stderr, "outTime changed\n");
- #endif
- }
- if (obj->maxOutputLevel.getValue() != obj->oldmaxOutputLevel) {
- obj->oldmaxOutputLevel = obj->maxOutputLevel.getValue();
- obj->molchange = 1;
- #ifdef DEBUG
- fprintf(stderr, "max output changed\n");
- #endif
- }
-
- }
-
- void AudioNode::play()
- {
- #ifdef DEBUG
- fprintf(stderr, "play()\n");
- #endif
- if (!pc) {
- pc = new PlayClass((char *) (filename.getValue()).getString());
- }
- // add stuff here to set pc fields
- if (fnamechange) {
- pc->setFilename((char *) (filename.getValue()).getString());
- fnamechange = 0;
- }
- if (tlchange) {
- pc->setTime((double) timeLength.getValue());
- tlchange = 0;
- }
- if (itchange) {
- pc->setInTime((double) inTime.getValue());
- itchange = 0;
- }
- if (otchange) {
- pc->setOutTime((double) outTime.getValue());
- otchange = 0;
- }
- if (molchange) {
- pc->setMaxOutputLevel((double) maxOutputLevel.getValue());
- molchange = 0;
- }
-
- if (rude.getValue() == YUP) {
- pc->setRude(TRUE);
- } else {
- pc->setRude(FALSE);
- }
-
- if (loop.getValue() == YUP) {
- pc->setLoop(TRUE);
- } else {
- pc->setLoop(FALSE);
- }
-
- if (sproc.getValue() == YUP) {
- pc->start();
- } else {
- pc->beginPlaying();
- }
- }
-
- void AudioNode::stop()
- {
- #ifdef DEBUG
- fprintf(stderr, "stop()\n");
- #endif
- if (!pc) return;
-
- pc->stop();
- }
-
- void AudioNode::fade()
- {
- #ifdef DEBUG
- fprintf(stderr, "stop()\n");
- #endif
- if (!pc) return;
-
- pc->fadeOut();
- }
-
- void AudioNode::pause()
- {
- #ifdef DEBUG
- fprintf(stderr, "unpause()\n");
- #endif
- if (!pc) return;
-
- pc->pause();
- }
-
- void AudioNode::unpause()
- {
- #ifdef DEBUG
- fprintf(stderr, "unpause()\n");
- #endif
- if (!pc) return;
-
- pc->unpause();
- }
-
- int AudioNode::donep()
- {
- // add stuff here to really check if done
- return pc->donep();
- }
-
- void AudioNode::setNoDone(short nd)
- {
- #ifdef DEBUG
- fprintf(stderr, "setNoDone()\n");
- #endif
- if (!pc) return;
-
- pc->setNoDone(nd);
- }
-